gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\generalp\cerror.m

    function [error,nbad,nall]=cerror(Ireal,Iclass,Class)
% [error,nbad,nall]=cerror(Ietalon,Iclass,Class)
%
% CERROR computes different components in vector Ireal and Iclass.
%
%   This function serves for evaluating of classification error.
%   If vector Ireal contains real class labels (from teacher) and
%   vector Iclass contains labels generated by a classifier then
%   the function computes classification error.
%
% Input:
%   CERROR(Ireal,Itest)
%
%   Ireal [1xK], Iclass [1xK] - these vectors contain K arbitrary
%      numbers (but a class labels they contain integers usually).
%
%   CERROR(Ireal,Iclass,Class) looks at components with the value
%   equal to the number Class [1x1].
%
% Output:
%   error [1x1] contains ratio between different components and all the
%   components. It is a positive real number from 0 to 1.
%   nbad [1x1] number of different components.
%   nall [1x1] number of all components.
%
% Example
%   Ireal =[1,1,1,2,2,2,2,2]
%   Iclass=[2,1,1,2,2,2,2,1]
%
%   [error,nbad,nall]=cerror(Ireal,Iclass) returns error=2/6, nbad=2, nall=6.
%
%   [error,nbad,nall]=cerror(Ireal,Iclass,1) returns error=1/3, nbad=1, nall=3.
%

% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis) 02.01.2000
% Modifications
% 24. 6.00 V. Hlavac, comments polished.

if length(Ireal) ~= length(Iclass),
   error('Input vectors length must agree.');
   return;
end

if nargin < 3,
   nall=length(Ireal);
   nbad=nall-length(find((Ireal(:)-Iclass(:))==0));
   if nall==0,
      error=0;
   else
      error=nbad/nall;
   end
else
   ci=find(Ireal(:)==Class);
   nall=length(ci);
   nbad=nall-length(find(Iclass(ci)==Class));
   if nall==0,
      error=0;
   else
      error=nbad/nall;
   end
end